package com.zhangyongyi.carhome.fragment.findcar;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.adapter.findcar.FindCarAdapter;
import com.zhangyongyi.carhome.fragment.findcar.episode.EpisodeFragment;
import com.zhangyongyi.carhome.fragment.findcar.story.StoryFragment;

import java.util.ArrayList;


public class FindCarFragment extends Fragment {
    private ArrayList<Fragment> datas;
    private FindCarAdapter adapter;
    private TabLayout tabLayout;
    private ViewPager viewPager;




    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_find_car,null);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        datas = new ArrayList<>();
        datas.add(new EpisodeFragment());//段子
        datas.add(new StoryFragment());//趣图








        viewPager = (ViewPager) view.findViewById(R.id.viewPager);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);

        adapter = new FindCarAdapter(getChildFragmentManager(),datas,getActivity());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        //蓝色
        tabLayout.setSelectedTabIndicatorColor(Color.BLUE);

        for(int i = 0;i < tabLayout.getTabCount();i++){//判断tablayout有几个菜单数量
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null){
                tab.setCustomView(adapter.getTabView(i));//将adapter设置好的获取图片和文字的方法设置到视图中
            }
        }


    }
}
